Skip to content

Avoid frozen-string-literal warnings in Ruby 3.4#27

Open
kindjar wants to merge 3 commits intoopencoconut:masterfrom
moonbaseai:ruby-3-4-frozen-strings
Open

Avoid frozen-string-literal warnings in Ruby 3.4#27
kindjar wants to merge 3 commits intoopencoconut:masterfrom
moonbaseai:ruby-3-4-frozen-strings

Conversation

@kindjar
Copy link
Copy Markdown

@kindjar kindjar commented Apr 9, 2026

In Ruby 3.4, string literals are "chilled" by default, and if chilled strings are modified, a warning is emitted (see https://bugs.ruby-lang.org/issues/20205 for details). There are a couple of places in webvtt-ruby where a variable is initialized with an empty string literal and then appended, which triggers these warnings. The clearest fix for these is to replace the empty string literal with a call to String.new.

I'm hoping you are open to a pull request to address these warnings under Ruby 3.4?

I also discovered that one of the test cases wasn't cleaning up files the way other tests did, and addressed that.

And finally, I added the frozen_string_literal: true pragma to the ruby source files, which will cause any future attempts to modify a frozen string literal to raise an error, so that no other warning sneak in.

I'm happy to pare this down if you prefer not add the pragma.

Thanks for your consideration!

kindjar added 3 commits April 9, 2026 10:28
Since the same files would be written—and cleaned up—by several other tests, these files might or might not be left behind, depending on the order in which tests were run.
In Ruby 3.4, by default string literals are “chilled” and if a chilled string is modified, a warning is emitted (https://bugs.ruby-lang.org/issues/20205). Replace string literals that are intended to be modified with a call to String.new, which produces a fresh mutable string each invocation.
This pragma is supported back to Ruby 2.3 and prohibits modifying string literals, which will (someday?) be frozen by default in Ruby.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant